#pragma once
#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;

#include<cstdlib>
#include<stdio.h>
#include<ctime>

#define DSIZE 1000000

void tTest_Deque() {
	deque<string> d;

	clock_t timeStart = clock();
	cout << "开始时间: " << timeStart << endl;

	char buf[10];
	for (int i = 0; i < DSIZE; i++) {
		try {
			snprintf(buf, 10, "%d", rand());	//根据格式化得到字符串
			d.push_back(buf);
		}
		catch (exception& p) {
			cout << "i= " << i << " " << p.what() << endl;
			abort();	//退出程序
		}
	}

	cout << "deque 赋值所需要时间: " << clock() - timeStart << endl;
	cout << "deque 大小: " << d.size() << endl;
	cout << "deque 起点元素: " << d.front() << endl;
	cout << "deque 终点元素: " << d.back() << endl;
	cout << "deque 最大大小: " << d.max_size() << endl;
	
	string target;
	cin >> target;

	//全局查找
	timeStart = clock();
	deque<string>::iterator pItem = ::find(d.begin(), d.end(), target);
	cout << "find 所需要时间: " << clock() - timeStart << endl;

	if (pItem != d.end())
		cout << "找到元素: " << *pItem << endl;
	else
		cout << "找不到" << endl;


	//sort 全局排序
	timeStart = clock();
	sort(d.begin(), d.end());
	cout << "sort 所需要时间: " << clock() - timeStart << endl;
}
